package com.ruoyi.web.controller.qiushi.equipment;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.qiushi.domain.equipment.QiushiDeviceOut;
import com.ruoyi.qiushi.domain.equipment.QiushiDeviceType;
import com.ruoyi.qiushi.service.equipment.IQiushiDeviceOutService;
import com.ruoyi.qiushi.service.equipment.IQiushiDeviceTypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备出库Controller
 *
 * @author ruoyi
 * @date 2023-12-22
 */
@RestController
@RequestMapping("/qiushi/equipment/qiushideviceout")
public class QiushiDeviceOutController extends BaseController {
    @Autowired
    private IQiushiDeviceOutService qiushiDeviceOutService;
    @Autowired
    private IQiushiDeviceTypeService qiushiDeviceTypeService;

    /**
     * 查询设备出库列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushideviceout:list')")
    @GetMapping("/list")
    public TableDataInfo list(QiushiDeviceOut qiushiDeviceOut) {
        startPage();
        List<QiushiDeviceOut> list = qiushiDeviceOutService.selectQiushiDeviceOutList(qiushiDeviceOut);
        return getDataTable(list);
    }

    /**
     * 导出设备出库列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushideviceout:export')")
    @Log(title = "设备出库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QiushiDeviceOut qiushiDeviceOut) {
        List<QiushiDeviceOut> list = qiushiDeviceOutService.selectQiushiDeviceOutList(qiushiDeviceOut);
        ExcelUtil<QiushiDeviceOut> util = new ExcelUtil<QiushiDeviceOut>(QiushiDeviceOut.class);
        util.exportExcel(response, list, "设备出库数据");
    }

    /**
     * 获取设备出库详细信息
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushideviceout:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(qiushiDeviceOutService.selectQiushiDeviceOutById(id));
    }

    /**
     * 新增设备出库
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushideviceout:add')")
    @Log(title = "设备出库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QiushiDeviceOut qiushiDeviceOut) {
        qiushiDeviceOut.setCreateTime(new Date());
        qiushiDeviceOut.setUpdateTime(new Date());
        return toAjax(qiushiDeviceOutService.insertQiushiDeviceOut(qiushiDeviceOut));
    }

    /**
     * 修改设备出库
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushideviceout:edit')")
    @Log(title = "设备出库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QiushiDeviceOut qiushiDeviceOut) {
        qiushiDeviceOut.setUpdateTime(new Date());
        return toAjax(qiushiDeviceOutService.updateQiushiDeviceOut(qiushiDeviceOut));
    }

    /**
     * 删除设备出库
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushideviceout:remove')")
    @Log(title = "设备出库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(qiushiDeviceOutService.deleteQiushiDeviceOutById(id));
    }
}
